package com.pactera.madp.cp.controller.sidebar.employee;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.common.log.annotation.SysLog;
import com.pactera.madp.cp.api.dto.emp.EmployeeFollowCreateDTO;
import com.pactera.madp.cp.api.dto.emp.EmployeeFollowUpdateDTO;
import com.pactera.madp.cp.service.EmployeeFollowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (CpEmployeeFollow)表控制层
 *
 * @author yushen.qi
 * @since 2021-06-29 15:06:39
 */
@RestController
@RequestMapping("/employeefollow")
@Api(value = "employeefollow", tags = "客户动态-跟进")
public class EmployeeFollowController {

    @Resource
    private EmployeeFollowService employeeFollowService;

    /**
     * 新增跟进
     *
     * @param dto
     * @return
     */
    @SysLog("新增跟进")
    @PostMapping
    @ApiOperation(value = "新增跟进")
    public R save(@RequestBody EmployeeFollowCreateDTO dto) {
        return employeeFollowService.insert(dto) ? R.ok("新增成功") : R.failed("新增失败");
    }

    /**
     * 删除跟进
     *
     * @param id
     * @return
     */
    @SysLog("删除跟进")
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除跟进")
    public R remove(@PathVariable Integer id) {
        return employeeFollowService.remove(id) ? R.ok("删除成功！") : R.failed("删除失败！");
    }

    /**
     * 查询跟进列表
     *
     * @param page
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "查询跟进列表")
    public R<IPage> listByPage(Page page, String wxExternalUserid, String wxUserId) {
        return R.ok(employeeFollowService.listByPage(page, wxExternalUserid, wxUserId));
    }

    /**
     * 更新跟进
     *
     * @param dto
     * @return
     */
    @SysLog("更新跟进")
    @PutMapping
    @ApiOperation(value = "更新跟进")
    public R update(@RequestBody EmployeeFollowUpdateDTO dto) {
        return employeeFollowService.update(dto) ? R.ok("更新成功") : R.failed("更新失败");
    }

    /**
     * 已跟进
     *
     * @param id
     * @return
     */
    @SysLog("已跟进")
    @GetMapping("/change/{id}")
    @ApiOperation(value = "已跟进")
    public R changState(@PathVariable Integer id) {
        employeeFollowService.state(id);
        return R.ok();
    }

}
